package cn.com.generaldata.os.service.indicator_evaluation.industry_structure_analysis;

import org.apache.commons.lang3.Validate;

import cn.com.generaldata.jsme_indicator_system.entity.IndicatorEvaluation;
import cn.com.generaldata.os.service.indicator_constant.ProvinceIndicatorConstant;
import cn.com.generaldata.os.service.indicator_evaluation.IndicatorEvaluationCalculateService;
import cn.com.generaldata.os.vo.IndicatorAccountVO;

/**
 * 第二产业比较劳动生产率评估指标计算类.
 */
public class SecondCompareWorkProductivityCalculateService extends IndicatorEvaluationCalculateService {

	private String FirstAddName = ProvinceIndicatorConstant.FIRST_INDICATOR_NAME;
	private String SecondAddName = ProvinceIndicatorConstant.SECOND_INDICATOR_NAME;
	private String ThirdAddName = ProvinceIndicatorConstant.THIRD_INDICATOR_NAME;
	private String FirstEnployedName = ProvinceIndicatorConstant.FIRST_EMPLOYED_INDICATOR_NAME;
	private String SecondEnployedName = ProvinceIndicatorConstant.SECOND_EMPLOYED_INDICATOR_NAME;
	private String ThirdEnployedName = ProvinceIndicatorConstant.THIRD_EMPLOYED_INDICATOR_NAME;

	@Override
	protected Double calculate(IndicatorEvaluation indicator, IndicatorAccountVO indicatorAccountVO) {

		Double firstAddValue = getBaseIndicatorVal(indicatorAccountVO, indicatorAccountVO.getYear(), FirstAddName);
		Double secondAddValue = getBaseIndicatorVal(indicatorAccountVO, indicatorAccountVO.getYear(), SecondAddName);
		Double thirdAddValue = getBaseIndicatorVal(indicatorAccountVO, indicatorAccountVO.getYear(), ThirdAddName);
		Double firstEnployed = getBaseIndicatorVal(indicatorAccountVO, indicatorAccountVO.getYear(), FirstEnployedName);
		Double secondEnployed = getBaseIndicatorVal(indicatorAccountVO, indicatorAccountVO.getYear(),
				SecondEnployedName);
		Double thirdEnployed = getBaseIndicatorVal(indicatorAccountVO, indicatorAccountVO.getYear(), ThirdEnployedName);
		Double sumAddValue = firstAddValue + secondAddValue + thirdAddValue;
		Double sumEnployed = firstEnployed + secondEnployed + thirdEnployed;
		// if (secondEnployed.equals(Double.valueOf(0)) || sumEnployed.equals(Double.valueOf(0))
		// || sumAddValue.equals(Double.valueOf(0))) {
		// return Double.valueOf(0);
		// }
		Validate.isTrue(!(Double.valueOf(0).equals(secondEnployed)));
		Validate.isTrue(!(Double.valueOf(0).equals(sumEnployed)));
		Validate.isTrue(!(Double.valueOf(0).equals(sumAddValue)));
		return (secondAddValue / secondEnployed) / (sumAddValue / sumEnployed);

	}

	private Double getBaseIndicatorVal(IndicatorAccountVO indicatorAccountVO, int year, String name) {
		Double result = getInputOrAccountingIndicatorValue(indicatorAccountVO, year, name);
		return result == null ? 0d : result;
	}

}
